package util
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;
	
	import mx.core.BitmapAsset;
	import mx.events.ResizeEvent;
	
	public class backGroundFill { 
		private var gp:Graphics;  // 배경색이 칠해질 영역
		private var bg:BitmapAsset;
		private var tg:Object;
		private var _alphaNum:Number;
		
		public function backGroundFill(bgImg:Class,Target:Object,alphaNum:Number=1) {
			bg = new bgImg as BitmapAsset // 이미지를 지정한다.
			gp = Target.graphics
			tg = Target
			_alphaNum = alphaNum;
			// 이젠 칠하자
			paintBG()
			Target.addEventListener(ResizeEvent.RESIZE,paintBG)
		}
		
		private function paintBG(event:ResizeEvent=null):void {
			gp.clear()			
			gp.beginBitmapFill(SetAlpha(bg.bitmapData) )
			gp.drawRect(0,0,tg.width,tg.height)			
			gp.endFill()
			return
		}
		
		private function SetAlpha(bmd:BitmapData):BitmapData
		{
			var rec:Rectangle = new Rectangle(0, 0, bmd.width, bmd.height);
			var ct:ColorTransform = new ColorTransform();
			ct.alphaMultiplier = _alphaNum; 
			bmd.colorTransform(rec, ct);
			return bmd;
		}
	}
}